const express = require('express');
const router = express.Router();
const { meetingModel } = require('../model/db');

// 获取最近会议
router.get('/recent', async (req, res) => {
  try {
    const recentMeetings = await meetingModel.find().sort({ startTime: -1 }).limit(10);
    res.send({ code: 200, data: recentMeetings });
  } catch (error) {
    console.error('获取最近会议失败:', error);
    res.status(500).send({ code: 500, msg: '服务器内部错误' });
  }
});

// 创建会议
router.post('/create', async (req, res) => {
  const { title, startTime, endTime } = req.body;
  try {
    const newMeeting = await meetingModel.create({
      title,
      startTime,
      endTime
    });
    res.send({ code: 201, msg: '会议创建成功', meeting: newMeeting });
  } catch (error) {
    console.error('创建会议失败:', error);
    res.status(500).send({ code: 500, msg: '服务器内部错误' });
  }
});

module.exports = router;